package com.hrbxlh.actionImpl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hrbxlh.dao.*;
import com.hrbxlh.util.*;
import jxl.Sheet;
import jxl.Workbook;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.*;


@Component("classActionImpl")
@Transactional
public class ClassActionImpl {

	@Resource(name = "classDao")
	private ClassDao classDao;

	@Resource(name = "memberDao")
	private MemberDao memberDao;

	@Resource(name = "professionDao")
	private ProfessionDao professionDao;

	@Resource(name = "departMentDao")
	private DepartMentDao departMentDao;

	@Resource(name = "relStuClassDao")
	private RelStuClassDao relStuClassDao;

	@Resource(name = "relationDao")
	private RelationDao relationDao;

	@Resource(name = "courseDao")
	private CourseDao courseDao;

	@Resource(name="sourceDao")
	private SourceDao sourceDao;

	@Resource(name="chapterDao")
	private ChapterDao chapterDao;

	@Autowired
	private CourseActionImpl courseActionImpl;

	@Autowired
	@Qualifier("homeworkTestDao")
	private HomeworkTestDao homeworkTestDao;

	@Resource(name="questionDao")
	private QuestionDao questionDao;

	@Autowired
	@Qualifier("memberActionImpl")
	private MemberActionImpl memberActionImpl;

	Logger logger = Logger.getLogger(ClassActionImpl.class.getName());

	/**
	 * @description 添加班级的方法，参数key与数据库column对应即可。
	 * @param Map<String,Object> paramMap
	 * @return Map<String, String> result true成功，false失败 errorMsg错误信息
	 * @throws Exception
	 */
	public Map<String, Object> addClass(Map<String, Object> paramMap) throws Exception {

		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			//通过班级名查询班级信息
			List<Map<String, Object>> classList = classDao.getClassByClassName((String) paramMap.get("className"));
			if(paramMap.get("relationList") == null){
				//判断班级名重复
				if (classList != null && classList.size() != 0) {
					resultMap.put("result", false);
					resultMap.put("failMsg", "该班级名已存在");
				} else {
					//添加班级信息，返回班级id
					classDao.addClass(paramMap);
					resultMap.put("result", true);
				}
			}else {
				//添加班级，判断有没有重复的课程
				boolean repeatResult = this.checkRepeat((List<Map<String, Object>>) paramMap.get("relationList"));
				if (repeatResult) {
					//判断班级名重复
					if (classList != null && classList.size() != 0) {
						resultMap.put("result", false);
						resultMap.put("failMsg", "该班级名已存在");
					} else {
						//添加班级信息，返回班级id
						classDao.addClass(paramMap);
						for (Map<String, Object> map : (List<Map<String, Object>>) paramMap.get("relationList")) {
							paramMap.put("stuorteaId", map.get("stuorteaId"));
							paramMap.put("selectMark", 1);
							paramMap.put("courseId", map.get("courseId"));
							//添加表单关联关系  参数paramMap stuorteaId classId  courseId
							classDao.saveClassRelation(paramMap);
							//添加教师与班级的关联信息  注意标识
							relationDao.saveRelClassTeaCourse(paramMap);
							//查询当前教师当前课程是否已经有试题And将班级与试卷的关联插入关联表中
							addReOnlineClass(paramMap);
							//添加课与教师的权重（给默认）
							paramMap.put("classPerformance",0.4);
							paramMap.put("excellent",100);
							paramMap.put("good",90);
							paramMap.put("inso",80);
							paramMap.put("bad",60);
							paramMap.put("souceMark",0);
							//查询这个教师这个课程是否已经存在权重
							Map<String,Object> sourceMap = sourceDao.getProWedith(paramMap);
							if(sourceMap==null||sourceMap.size()==0){
								sourceDao.addSorceSet(paramMap);
							}
							//添加老师与课的关系  注意有没有， 注意标识
							List<Map<String, Object>> relCouTeaList = relationDao.getRelCourseTea(paramMap);
							if (relCouTeaList == null || relCouTeaList.size() == 0) {
								relationDao.saveRelCourseTea(paramMap);
							} else {
								//如果之前这个老师和这个课的关联是2，把标识改为3
								if (Integer.parseInt(relCouTeaList.get(0).get("couSelectMark").toString()) == 2) {
									//将couSelectMark改为3
									paramMap.put("selectMark", 3);
									relationDao.saveSelectMark(paramMap);
								}
								//修改上课标识inMark为0
								paramMap.put("inMark", 0);
								relationDao.saveInMarkReMark(paramMap);
							}
							paramMap.put("selectMark", 1);
							//添加课与班级的关系  注意标识
							List<Map<String, Object>> relCouClassList = relationDao.getRelCourseClass(paramMap);
							if (relCouClassList == null || relCouClassList.size() == 0) {
								relationDao.saveRelCourseClass(paramMap);
							}
							//如果之前这个课是2要吧2改为3
							Map<String, Object> courseMap = courseDao.getCourseDetail(paramMap);
							if (Integer.parseInt(courseMap.get("selectMark").toString()) == 2) {
								paramMap.put("selectMark", 3);
								courseDao.saveSelectMark(paramMap);
							}
						}
						resultMap.put("result", true);
					}
				} else {
					resultMap.put("result", false);
					resultMap.put("failMsg", "课程选择重复");
				}
			}
			logger.info("添加班级信息，参数为："+paramMap.toString());
		} catch (Exception e) {
			throw e;
		}
		return resultMap;
	}

	/**
	 * @description 查询班级的方法
	 * @param Map<String,Object> paramMap,如果有参数，要与数据库column值相同。
	 * @return List<Map<String, Object>> 班级集合
	 * @throws Exception
	 */
	public Map<String, Object> getClass(Map<String, Object> paramMap) throws Exception {

		List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
		Map<String, Object> returnmap = new HashMap<String,Object>();
		try {
			int deaprtMentId = 0;
			resultList = classDao.getClass(paramMap);
			if(resultList!=null&&resultList.size()!=0){
				deaprtMentId = (Integer)resultList.get(0).get("departmentId");
			}
			paramMap.put("departmentId", deaprtMentId);
			//通过院系id查询旗下的所有专业集合
			List<Map<String, Object>> proList = professionDao.getProfessionList(paramMap);
			returnmap.put("resultList", resultList);
			returnmap.put("proList", proList);
		} catch (Exception e) {
			throw e;
		}
		return returnmap;
	}


	/**
	 * @description 修改班级的方法，参数key与数据库column一致。
	 * @param Map<String,Object> paramMap
	 * @return boolean (true 成功 ,false失败)
	 * @throws Exception
	 */
	public Map<String, Object> saveClass(Map<String,Object> paramMap) throws Exception {

		Map<String,Object> returnMap = new HashMap<String,Object>();
		try {
			//修改班级中的专业院系之后，在学生表里面把院系专业修改掉
			memberDao.saveStuProAndDepartId(paramMap);
			//判断有没有新添加的，如果没有
			if((List<Map<String, Object>>)paramMap.get("addList") == null){
				//修改班级基本信息
				classDao.saveClass(paramMap);
				returnMap.put("result", true);
				//删除要删除的中间表关联信息
				Map<String,Object> delMap = this.delClassRelations(paramMap);
				if(!Boolean.parseBoolean(String.valueOf(delMap.get("result")))){
					return delMap;
				}
				//有新添加的
			}else{
				//判断新添加的有没有重复的课程
				boolean repeatResult = this.checkRepeat((List<Map<String, Object>>)paramMap.get("addList"));
				if(repeatResult){
					//判断修改的班级名是否已存在
					Map<String,Object> classMap = classDao.saveGetClassByClassName(paramMap);
					if(classMap==null){
						//删除要删除的中间表关联信息
						Map<String,Object> delMap = this.delClassRelations(paramMap);
						if(!Boolean.parseBoolean(String.valueOf(delMap.get("result")))){
							return delMap;
						}
						//查询原来就有的这个班级的关联信息append到新加的集合中，然后用哪个方法判断是不是重复，然后才能走下面
						List<Map<String, Object>> addBeforeList = relationDao.getClassRelationByClassId(paramMap);
						addBeforeList.addAll((List<Map<String, Object>>)paramMap.get("addList"));
						boolean repeatResultUse = this.checkRepeat(addBeforeList);
						if(repeatResultUse){
							//修改班级基本信息
							classDao.saveClass(paramMap);
							returnMap.put("result", true);
							//添加新添加的关联信息
							if(paramMap.get("addList") != null){
								for(Map<String, Object> map : (List<Map<String, Object>>)paramMap.get("addList")){
									paramMap.put("stuorteaId", map.get("stuorteaId"));
									paramMap.put("selectMark", 1);
									paramMap.put("courseId", map.get("courseId"));
									paramMap.put("classId", paramMap.get("classId"));
									//添加表单关联关系  参数paramMap stuorteaId classId  courseId
									classDao.saveClassRelation(paramMap);
									//添加课与教师的权重（给默认）
									paramMap.put("classPerformance",0.4);
									paramMap.put("excellent",100);
									paramMap.put("good",90);
									paramMap.put("inso",80);
									paramMap.put("bad",60);
									paramMap.put("souceMark",0);
									//查询这个教师这个课程是否已经存在权重
									Map<String,Object> resultMap = sourceDao.getProWedith(paramMap);
									if(resultMap==null||resultMap.size()==0){
										sourceDao.addSorceSet(paramMap);
									}
									//0620添加教师与班级的关联信息  注意标识
									List<Map<String, Object>> relClassTeaList = relationDao.getRelClassTea(paramMap);
									if(relClassTeaList == null || relClassTeaList.size() == 0){
										relationDao.saveRelClassTeaCourse(paramMap);
										//查询当前教师当前课程是否已经有试题And将班级与试卷的关联插入关联表中
										addReOnlineClass(paramMap);
									}
									//0620 end
									//添加老师与课的关系  注意有没有， 注意标识
									List<Map<String, Object>> relCouTeaList = relationDao.getRelCourseTea(paramMap);
									if(relCouTeaList == null || relCouTeaList.size() == 0){
										relationDao.saveRelCourseTea(paramMap);
									}else{
										//如果之前这个老师和这个课的关联是2，把标识改为3
										if(Integer.parseInt(relCouTeaList.get(0).get("couSelectMark").toString()) == 2){
											//将couSelectMark改为3
											paramMap.put("selectMark", 3);
											relationDao.saveSelectMark(paramMap);
										}
										//如果是课程的录入人，需要将inMark改为0
										Map<String, Object> paramUseMap = new HashMap<String, Object>();
										paramUseMap.put("inMark", 0);
										paramUseMap.put("stuorteaId", paramMap.get("stuorteaId"));
										paramUseMap.put("courseId", paramMap.get("courseId"));
										relationDao.saveInMarkReMark(paramUseMap);
									}
									paramMap.put("selectMark", 1);
									//添加课与班级的关系  注意标识
									List<Map<String, Object>> relCouClassList = relationDao.getRelCourseClass(paramMap);
									if(relCouClassList == null || relCouClassList.size() == 0){
										relationDao.saveRelCourseClass(paramMap);
									}else{
										//如果原来存在课程与班级的关系，将结课标识改为0
										paramMap.put("classEndMark", 0);
										courseDao.endCourseClass(paramMap);
									}
									//添加这个班级下的学生与这个课的关联信息
									//查询原来是不是存在这个班级的学生的关联信息（如果有课程和班级的关联关系，就说明已经存在了，如果没有就是没有）
									//查询这个班级下的学生
									List<Map<String, Object>> stuList = relationDao.getStuByClassId(paramMap);
									//0508如果学生是空的不添加
									if(stuList != null && stuList.size() != 0 ){
										Map<String, Object> stuReCourseMap ;
										for(int j = 0;j < stuList.size(); j++){
											stuReCourseMap = new HashMap<String, Object>();
											stuReCourseMap.put("stuorteaId", stuList.get(j).get("stuorteaId"));
											stuReCourseMap.put("courseId", map.get("courseId"));
											stuReCourseMap.put("selectMark", 1);
											//查询这个学生这个课程之前有没有关联信息，如果没有就添加
											Map<String, Object> reListMap = relStuClassDao.getRelStuCouByStuCou(stuReCourseMap);
											if(reListMap == null){
												relationDao.saveRelCourseTea(stuReCourseMap);
											}else{
												//如果存在这个学生与这个课的关联，把结课标识改为0
												stuReCourseMap.put("endMark", 0);
												classDao.saveRelStuCouEndMark(stuReCourseMap);
											}
										}
									}
									//如果之前这个课是2要吧2改为3
									Map<String, Object> courseMap = courseDao.getCourseDetail(paramMap);
									if(Integer.parseInt(courseMap.get("selectMark").toString()) == 2){
										paramMap.put("selectMark", 3);
										courseDao.saveSelectMark(paramMap);
									}
								}
							}
						}else{
							returnMap.put("result", false);
							returnMap.put("failMsg", "课程选择重复");
						}
					}else{
						returnMap.put("result", false);
						returnMap.put("failMsg", "班级名重复，修改失败");
					}
				}else{
					returnMap.put("result", false);
					returnMap.put("failMsg", "课程选择重复");
				}
			}
			logger.info("修改班级，参数为："+paramMap.toString());
		} catch (Exception e) {
			throw e;
		}
		return returnMap;
	}

	/**
	 * @description 删除班级的方法，传的是每个班级的id。
	 * @param .List<Integer> paramList 班级id集合
	 * @return boolean (true 成功 ,false失败)
	 * @throws Exception
	 * 备注：删除班级的时候直接把旗下的学生直接删除
	 */
	public boolean delClass(List<String> paramList,int marks) throws Exception {

		boolean resultFlag = false;
		try {
			//3.0删除作业信息
			//查询所有这个班级学生的作业信息
			List<Map<String, Object>> workList = homeworkTestDao.getWorkByClasses(paramList);
			DelWorkFileUtil delWorkFileUtil = new DelWorkFileUtil();
			String[] keysArray = {"server_address", "project_name","tomcatUrl"};
			Map<String, Object> urlmap = ConfigFileUtil.getFileMessage("UtilFile.properties", keysArray);
			String url = (String)urlmap.get("tomcatUrl")+(String)urlmap.get("project_name")+"upload/stuwork/";
			delWorkFileUtil.delWorkFile(workList, "taskAddress", "convertFile", url);
			//解除某班级下所有学生的虚拟机绑定
			Map<String, Object> vmParam = new HashMap<String, Object>();
			vmParam.put("classId", paramList.get(0));
			//通过班级id查人员id的集合
			List<Map<String,Object>> idList = memberDao.getUseIdList(paramList);
			if(!CollectionUtils.isEmpty(idList)){
				//删除这些学生的保存的实验信息（不是上传的）
				Map<String, Object> delMap = new HashMap<String, Object>();
				delMap.put("delType", 5);
				delMap.put("list", idList);
				homeworkTestDao.delStuTestHistory(delMap);
			}
			if(marks==1){
				//调用删除所有相关的方法
				resultFlag = this.delMethod(paramList,marks,vmParam,idList, paramList.get(0));
			}if(marks==2){
				resultFlag = this.delMethod(paramList,marks,vmParam,idList, paramList.get(0));
			}
			logger.info("删除班级，参数为:"+paramList.toString());
		} catch (Exception e) {
			throw e;
		}
		return resultFlag;
	}

	//删除班级所有相关的方法
	public boolean delMethod(List<String> paramList,int marks,Map<String, Object> vmParam,List<Map<String,Object>> idList, Object classId){
		boolean flag = false;
		try{
			//1214
			this.saveClassesMark(paramList);
			//1214
			/*//1214begin通过classId集合将所有班级的所有课程，老师的关联进行修改，还有course类型
			//this.saveTeachMark(paramList);
//			Map<String, Object> paramMap = new HashMap<String, Object>();
//			paramMap.put("classId", classId);
//			List<Map<String, Object>> teacouList = classDao.getClassRelation(paramMap);
//			//修改这些教师与这些课程的关联，（注意判断是不是录入教师，如果是，修改标识即可，不删除，如果不是录入教师，删除关联课程的信息）
//			this.delTeaAndCouRelation(teacouList);
			*/
			//1214end
			//删除班级学生关联表
			flag =	relStuClassDao.delRelStuClassByClassId(paramList);
			//删除课程班级关联表
			flag = relStuClassDao.delRelcourseClassByClassId(paramList);
			//通过班级号删除消息班级关联表
			flag = relStuClassDao.delRelnotClassByClassId(paramList);
			//通过班级号删除教师班级关联表
			flag =	relStuClassDao.delRelteaClassByClassId(paramList);
			//删除人与课程的关联表
			if(idList!=null&&idList.size()!=0){
				flag =relStuClassDao.delRelstuCouByStuorteaIdClass(idList);
				//删除学生成绩表
				flag =	sourceDao.delStuSoruceBystuorteaId(idList);
			}
			//批量删除classrelation表中的数据,参数是班级id
			classDao.delClassRelations(paramList);
			//删除班级下的人
			flag = memberDao.delMemberByClassId(paramList);
			//删除班级
			flag = classDao.delClass(paramList);
		}catch(Exception e){
			e.printStackTrace();
		}
		return flag;

	}

	//查询当前教师当前课程是否已经有试题And将班级与试卷的关联插入关联表中
	public void addReOnlineClass(Map<String,Object> paramMap){
		try{
			List<Map<String,Object>> testList = questionDao.getOnlineQuestionByOnCourseId(paramMap);
			if(testList!=null&&testList.size()!=0){
				//20180804修改:将原试卷复制一份，形成每个班级对应一份试卷
				paramMap.put("list",testList);
				paramMap.put("mark",0);
				questionDao.addCopyOnlineQuestion(paramMap);
				//通过被复制的试卷id查询复制好的试卷id
				List<Map<String,Object>> IdList = questionDao.getAllCopyQuIdList(paramMap);
				//将试卷与班级的关联加入关联表中
				paramMap.put("IdList",IdList);
				paramMap.put("mark",1);
				questionDao.addreClassOnlineByListId(paramMap);
				/*//说明教师已经出试题，需要将试题主键插入关联表中
				paramMap.put("list",testList);
				paramMap.put("mark",1);//区分用哪个sql
				questionDao.addreClassOnlineByListId(paramMap);*/
			}
		}catch (Exception e){
			e.printStackTrace();
		}
	}

	/**xzx
	 * @description 删除班级调用的修改关联的方法
	 * */
	public boolean saveClassesMark(List<String> paramList){
		boolean result = false;
		try {
			Map<String, Object> map = new HashMap<String, Object>();
			List<Map<String, Object>> relationList = classDao.getClassRelationByList(paramList);
			if(relationList != null || relationList.size() != 0){
				map.put("delList", relationList);
				this.delClassRelations(map);
			}
			result = true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
		return result;
	}

	/**
	 * @description 删除这些教师与这些课程的关联，（注意判断是不是录入教师，如果是，修改标识即可，不删除，如果不是录入教师，删除关联课程的信息）
	 * @param
	 * @return
	 * @throws Exception
	 */
	public boolean delTeaAndCouRelation(List<Map<String, Object>> paramList) throws Exception{
		boolean result = false;
		try{
			Map<String, Object> courseMap = new HashMap<String, Object>();
			//查询每一个教师与课程的关系，如果是录入教师 修改关联信息，如果不是录入教师，将教师课程关联删除
			for(Map<String, Object> map : paramList){
				//查询这个课程全部信息
				courseMap = courseDao.getCourseDetail(map);
				//如果是录入人，修改标识，
				if(map.get("stuorteaId").toString().equals(courseMap.get("stuorteaId").toString())){
					map.put("inMark", 1);
					relationDao.saveInMarkReMark(map);
					//不是录入人信息，将关联删除
				}else{
					relationDao.delCourseReTeacher(map);
				}
			}
			result = true;
		}catch(Exception e){
			throw e;
		}
		return result;
	}


	/**
	 * @description 查询班级列表的方法，分页。
	 * @param Map<String,Object> paramMap 当前页数：pageNow，每页条数：pageSize，其他条件与column列值要一致。
	 * @return Map<String, Object> memberList：班级集合，pageNow：当前页数，totalPage：总页数
	 * @throws Exception
	 */
	public Map<String, Object> getClassList(Map<String, Object> paramMap) throws Exception {

		Map<String, Object> returnMap = new HashMap<String, Object>();
		List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
		try {
			//获取分页数据
			int pageNow = (Integer)paramMap.get("pageNow");
			int pageSize = (Integer)paramMap.get("pageSize");
			int startNum = pageUtil.getSqlStartPos(pageNow, pageSize);
			paramMap.put("startNum", startNum);
			//查询所有班级
			List<Map<String, Object>> classList = classDao.getClass(paramMap);

			//将班级人数和班级合到一起放到新的集合里
			for(int i=0;i<classList.size();i++){
				Map<String, Object> newMap = new HashMap<String, Object>();
				//查询每个班级拥有的人数
				List<Map<String, Object>> coutList = memberDao.getStuCountByClassId(String.valueOf(classList.get(i).get("classId")));
				newMap.put("classId", classList.get(i).get("classId"));
				newMap.put("className", classList.get(i).get("className"));
				newMap.put("stuCount", coutList.get(0).get("stuCount"));
				newMap.put("departmentName", classList.get(i).get("departmentName"));
				newMap.put("professionName", classList.get(i).get("professionName"));
				resultList.add(newMap);
			}
			returnMap.put("classList", resultList);
			returnMap.put("pageNow", pageNow);

			//获取全部页数,全部班级名（搜素框用到的）
			paramMap.put("pageNow", 0);
			List<Map<String, Object>> allMemberList = classDao.getClass(paramMap);
			int totalPage = pageUtil.getTotalPage(allMemberList, pageSize);
			returnMap.put("totalPage", totalPage);
			returnMap.put("selectclaList", allMemberList);
			//获取所有院系信息
			paramMap.put("departmentName", "");
			paramMap.put("departmentId", "");
			List<Map<String, Object>> departMentList = departMentDao.getDepartMentList(paramMap);
			returnMap.put("departMentList", departMentList);

		} catch (Exception e) {
			throw e;
		}
		return returnMap;
	}

	/** sy
	 * @description 获取是这些班级的状态
	 * @param paramMap classId
	 * @return Map
	 * @throws Exception
	 */
	public Map<String, Object> getClassStateList(List<String> list) throws Exception {

		Map<String, Object> returnMap = new HashMap<String, Object>();
		List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
		try {
			//获取是这些班级是否存在以考试的班级
			List<Map<String, Object>> classList = classDao.getClassStateList(list);
			if(classList!=null&&classList.size()!=0){
				returnMap.put("result","fail");
				returnMap.put("msg","班级处于考试状态不可删除");
				return returnMap;
			}
			returnMap.put("result","success");
			returnMap.put("msg","");
		} catch (Exception e) {
			throw e;
		}
		return returnMap;
	}

	/*
	 * 导入
	 */
	public  Map<String,Object> imStuExcelByClass(String file,int classId,String type) throws Exception{
		//得到表格中所有的数据
		List<Map<String, Object>> listExcel= new ArrayList<Map<String, Object>>();
		//处理后数据的集合
		List<Map<String, Object>> finalList= new ArrayList<Map<String, Object>>();
		//查询每个班级对应的课程集合
		List<Map<String, Object>> courseList= new ArrayList<Map<String, Object>>();
		//参数map
		Map<String, Object> paramMap = new HashMap<String,Object>();

		//课程和学号map
		Map<String, Object> excelMap = new HashMap<String,Object>();
		paramMap.put("classId", classId);
		//返回结果的Map
		Map<String, Object> returnMap = new HashMap<String,Object>();
		boolean findFlag = false;
		boolean addFlag = false;
		boolean courseFlag = false;
		if(type.equals("1")){
			//查询每个班级对应的课程
			courseList =relStuClassDao.getRelCourseByClassId(paramMap);
			excelMap = this.getAllStudentByExcel(file,classId);
			listExcel = (List<Map<String, Object>>) excelMap.get("list");
			if(listExcel!=null&&listExcel.size()!=0){
				//查询当前班级所属的院系和专业
				Map<String,Object> classMap = classDao.getDeAndProByClassId(paramMap);
				if(courseList.size()!=0&&courseList!=null){
					for(int i=0;i<courseList.size();i++){
						for(int j=0;j<listExcel.size();j++){
							//课程和学号map
							Map<String, Object> couStuMap = new HashMap<String,Object>();
							couStuMap.put("stuorteaId", listExcel.get(j).get("stuorteaId"));
							couStuMap.put("courseId", courseList.get(i).get("courseId"));
							//将该班级所属院系加入学生中
							listExcel.get(j).put("professionId", classMap.get("professionId"));
							listExcel.get(j).put("departmentId", classMap.get("departmentId"));
							//查询当前人是否和当前课程有
							Map<String,Object> relMap = relStuClassDao.getRelStuCouByStuCou(couStuMap);
							if(relMap==null){
								finalList.add(couStuMap);
							}
						}
					}
					if(finalList!=null&&finalList.size()!=0){
						findFlag = true;
					}
				}else{
					for(int j=0;j<listExcel.size();j++){
						//将该班级所属院系加入学生中
						listExcel.get(j).put("professionId", classMap.get("professionId"));
						listExcel.get(j).put("departmentId", classMap.get("departmentId"));
					}
					addFlag = true;
					courseFlag = true;
				}
			}else{
				findFlag = false;
				addFlag = false;
			}
			if(findFlag){
				//将课程id和学生Id存入relstucou表中
				//通过d和学生Id查询relstucou表是否有数据
				for(int l=0;l<finalList.size();l++){
					Map<String,Object> relstucouMap = finalList.get(l);
					Map<String,Object> getRelStuCouMap =  relStuClassDao.getRelStuCouByStuCou(relstucouMap);
					if(getRelStuCouMap==null||getRelStuCouMap.size()==0){
						//添加操作
						courseFlag  = relStuClassDao.addRelstuCouByStuAndCou(relstucouMap);
					}else{
						//更新操作
						courseFlag  = relStuClassDao.upRelstuCouByStuAndCou(relstucouMap);
					}
				}

			}

		}if(type.equals("2")){
			excelMap = this.getAllByExcel(file);
			listExcel = (List<Map<String, Object>>) excelMap.get("list");
			if(listExcel!=null){
				//判断要导入的数据是否存在重复的工号
				for  ( int  i  =   0 ; i  <  listExcel.size()  -   1 ; i ++ )  {
					for  ( int  j  =  listExcel.size()  -   1 ; j  >  i; j -- )  {
						if  (String.valueOf(listExcel.get(j).get("stuorteaId")).equals(String.valueOf(listExcel.get(i).get("stuorteaId"))))  {
							//说明有重复数据
							returnMap.put("list", null);
							returnMap.put("errMsg", "工号存在重复，导入失败");
							return returnMap;
						}
					}
				}
			}
			addFlag = true;
			courseFlag = true;
		}

		if(!courseFlag&&finalList.size()!=0){
			returnMap.put("result","fail");
			returnMap.put("errMsg","添加课程出错");
		}if(!courseFlag&&finalList.size()==0&&addFlag){
			returnMap.put("result","fail");
			returnMap.put("errMsg","当前信息已被导入，请重新操作");
		}else{
			addFlag = true;
		}
       /*Map<String,Object>  sourceMap = new HashMap<String,Object>();
       sourceMap.put("classPerformance", 0.4);
	   sourceMap.put("excellent", 4);
	   sourceMap.put("good", 3);
	   sourceMap.put("inso", 2);
	   sourceMap.put("bad", 1);*/
		if(addFlag){

			String pwd = "";
			String password = "";
			if(listExcel!=null&&listExcel.size()!=0){
				for (int i=0;i<listExcel.size();i++) {
					String stuorteaId =String.valueOf(listExcel.get(i).get("stuorteaId")).trim();
					//查询这条记录是否已存在
					List<Map<String, Object>> memberList = memberDao.getMemberByStuorteaId(stuorteaId);
					if (memberList==null||memberList.size()==0) {
						listExcel.get(i).put("classId", classId);
						pwd = stuorteaId+"000000";
						password = DigestUtils.md5Hex(pwd);
						listExcel.get(i).put("password",password);
						//不存在就添加(数据库)
						boolean addflag = memberDao.addMember(listExcel.get(i));
						if(addflag&&type.equals("1")){
							//向relstuclass表插入数据
							Map<String, Object> paraMap = new HashMap<String,Object>();
							paraMap.put("classId", classId);
							paraMap.put("stuorteaId", stuorteaId);
							//查询这条记录是否存在relstuClass中
							Map<String,Object> relstuClassMap = relStuClassDao.getMapByStuIdAndClassId(paraMap);
							boolean flag = false;
							if(relstuClassMap==null||relstuClassMap.size()==0){
								//添加功能
								flag	= relStuClassDao.addRelStuClass(paraMap);
							}else{
								//更新操作
								flag	= relStuClassDao.updateRelStuClassByStuId(paraMap);
							}

							if(!flag){
								returnMap.put("result", "fail");
								returnMap.put("errMsg",excelMap.get("errMsg"));
							}else{
								returnMap.put("result", "success");
							}
						}if(addflag&&!(type.equals("1"))){
							//添加的是教师----将添加的教师对应的成绩设置设置为默认
                		 /*  sourceMap.put("stuorteaId", stuorteaId);
                		  boolean flag = sourceDao.addSorceSet(sourceMap);
                		  if(flag){
                			  returnMap.put("msg", "success");
                		  }else{
                			  returnMap.put("msg", "error");
                   		   	  returnMap.put("errMsg","成绩设置失败，添加教师失败");
                		  }*/
							returnMap.put("result", "success");
							returnMap.put("errMsg", "");
						}if(!addflag){
							returnMap.put("result", "fail");
							returnMap.put("errMsg",excelMap.get("errMsg"));
						}

					}else {
						listExcel.get(i).put("classId", classId);
						pwd = stuorteaId+"000000";
						password = DigestUtils.md5Hex(pwd);
						listExcel.get(i).put("password",password);
						if(type.equals("1")){
							//说明导入的是学生，判断当前导入的学生是否是在要导入的班级，如果当前学生在别的班级则提示存在重复数据，如果导入的是学生原来所在班级则做更新操作。
							if(Integer.parseInt(String.valueOf(memberList.get(0).get("classId")))!=classId){
								returnMap.put("result", "fail");
								returnMap.put("errMsg",listExcel.get(i).get("stuorteaId")+"学生已存在，导入失败");
								//手动进行事务回滚
								TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
								return returnMap;
							}
							returnMap.put("result", "fail");
							returnMap.put("errMsg","学号已存在，导入学生失败");
						}else{
							returnMap.put("result", "fail");
							returnMap.put("errMsg","工号已存在，导入教师失败");
						}

						//存在就更新
						/*20180912改成当数据库存在这条数据时，直接提示重复，不进行更新
						boolean saveflag = memberDao.saveMember(listExcel.get(i));
						if(!saveflag){
							returnMap.put("result", "fail");
							returnMap.put("errMsg",excelMap.get("errMsg"));
						}else{
							returnMap.put("result", "success");
						}*/
					}
				}
			}if(String.valueOf(excelMap.get("flag")).equals("success")){
				//说明当前用户要导入学生所属班级不存在
				returnMap.put("result","success");
			}if(listExcel==null||listExcel.size()==0&&!(String.valueOf(excelMap.get("flag")).equals("success"))){
				returnMap.put("result","fail");
				returnMap.put("errMsg",excelMap.get("errMsg"));

			}
		}else{
			returnMap.put("result","fail");
			if(returnMap.get("errMsg")!=""&&returnMap.get("errMsg")!=null){

			}else{
				returnMap.put("errMsg",excelMap.get("errMsg"));
			}

		}

		return returnMap;
	}

	/*
      * 多个班级一起导入学生
      */
	public  Map<String,Object> imStuExcelByManyClass(String file) throws Exception{
		//得到表格中所有的数据
		List<Map<String, Object>> listExcel= new ArrayList<Map<String, Object>>();
		//处理后数据的集合
		List<Map<String, Object>> finalList= new ArrayList<Map<String, Object>>();
		//查询每个班级对应的课程集合
		List<Map<String, Object>> courseList= new ArrayList<Map<String, Object>>();
		//参数map
		Map<String, Object> paramMap = new HashMap<String,Object>();
		//课程和学号map
		Map<String, Object> excelMap = new HashMap<String,Object>();

		//返回结果的Map
		Map<String, Object> returnMap = new HashMap<String,Object>();
		boolean findFlag = false;
		boolean addFlag = false;
		boolean courseFlag = false;
		excelMap = this.getAllStudentByManyClassExcel(file);
		listExcel = (List<Map<String, Object>>) excelMap.get("list");
		if(listExcel!=null){
			//判断要导入的数据是否存在重复的工号
			for  ( int  i  =   0 ; i  <  listExcel.size()  -   1 ; i ++ )  {
				for  ( int  j  =  listExcel.size()  -   1 ; j  >  i; j -- )  {
					if  (String.valueOf(listExcel.get(j).get("stuorteaId")).equals(String.valueOf(listExcel.get(i).get("stuorteaId"))))  {
						//说明有重复数据
						returnMap.put("list", null);
						returnMap.put("errMsg", "学号存在重复，导入失败");
						return returnMap;
					}
				}
			}
			//查询每个班级对应的课程
			courseList =relStuClassDao.getRelCourseByClassIdList(listExcel);
			if(courseList.size()!=0&&courseList!=null){
				for(int i=0;i<courseList.size();i++){
					for(int j=0;j<listExcel.size();j++){
						//课程和学号map
						Map<String, Object> couStuMap = new HashMap<String,Object>();
						couStuMap.put("stuorteaId", listExcel.get(j).get("stuorteaId"));
						couStuMap.put("courseId", courseList.get(i).get("courseId"));
						//查询当前人是否和当前课程是否有关联
						Map<String,Object> relMap = relStuClassDao.getRelStuCouByStuCou(couStuMap);
						if(relMap==null){
							finalList.add(couStuMap);
						}
					}
				}
				if(finalList!=null&&finalList.size()!=0){
					findFlag = true;
				}
			}else{
				addFlag = true;
				courseFlag = true;
			}
		}else{
			findFlag = false;
			addFlag = false;
		}
		if(findFlag) {
			//将课程id和学生Id存入relstucou表中
			//通过d和学生Id查询relstucou表是否有数据
			for (int l = 0; l < finalList.size(); l++) {
				Map<String, Object> relstucouMap = finalList.get(l);
				Map<String, Object> getRelStuCouMap = relStuClassDao.getRelStuCouByStuCou(relstucouMap);
				if (getRelStuCouMap == null || getRelStuCouMap.size() == 0) {
					//添加操作
					courseFlag = relStuClassDao.addRelstuCouByStuAndCou(relstucouMap);
				} else {
					//更新操作
					courseFlag = relStuClassDao.upRelstuCouByStuAndCou(relstucouMap);
				}
			}

		}

		if(!courseFlag&&finalList.size()!=0){
			returnMap.put("result","fail");
			returnMap.put("errMsg","添加课程出错");
		}if(!courseFlag&&finalList.size()==0&&addFlag){
			returnMap.put("result","fail");
			returnMap.put("errMsg","当前信息已被导入，请重新操作");
		}else{
			addFlag = true;
		}

		if(addFlag){
			String pwd = "";
			String password = "";
			if(listExcel!=null&&listExcel.size()!=0){
				for (int i=0;i<listExcel.size();i++) {
					String stuorteaId =String.valueOf(listExcel.get(i).get("stuorteaId"));
					//查询这条记录是否已存在
					List<Map<String, Object>> memberList = memberDao.getMemberByStuorteaId(stuorteaId);
					if (memberList==null||memberList.size()==0) {
						pwd = stuorteaId+"000000";
						password = DigestUtils.md5Hex(pwd);
						listExcel.get(i).put("password",password);
						//不存在就添加(数据库)
						boolean addflag = memberDao.addMember(listExcel.get(i));
						if(addflag){
							//向relstuclass表插入数据
							Map<String, Object> paraMap = new HashMap<String,Object>();
							paraMap.put("classId", listExcel.get(i).get("classId"));
							paraMap.put("stuorteaId", stuorteaId);
							//查询这条记录是否存在relstuClass中
							Map<String,Object> relstuClassMap = relStuClassDao.getMapByStuIdAndClassId(paraMap);
							boolean flag = false;
							if(relstuClassMap==null||relstuClassMap.size()==0){
								//添加功能
								flag	= relStuClassDao.addRelStuClass(paraMap);
							}else{
								//更新操作
								flag	= relStuClassDao.updateRelStuClassByStuId(paraMap);
							}

							if(!flag){
								returnMap.put("result", "fail");
								returnMap.put("errMsg",excelMap.get("errMsg"));
							}else{
								returnMap.put("result", "success");
							}
						}if(!addflag){
							returnMap.put("result", "fail");
							returnMap.put("errMsg",excelMap.get("errMsg"));
						}

					}else {
						pwd = stuorteaId+"000000";
						password = DigestUtils.md5Hex(pwd);
						listExcel.get(i).put("password",password);
						//说明导入的是学生，判断当前导入的学生是否是在要导入的班级，如果当前学生在别的班级则提示存在重复数据，如果导入的是学生原来所在班级则做更新操作。
						if(Integer.parseInt(String.valueOf(memberList.get(0).get("classId")))!= Integer.parseInt(String.valueOf(listExcel.get(i).get("classId")))){
							returnMap.put("result", "fail");
							returnMap.put("errMsg","学号为"+listExcel.get(i).get("stuorteaId")+"的学生已存在，导入失败");
							//手动进行事务回滚
							TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
							return returnMap;
						}
						returnMap.put("result", "fail");
						returnMap.put("errMsg","学号已存在，导入学生失败");
						//存在就更新
						/*20180912改成当数据库存在数据时，直接提示重复，不进行更新操作
						boolean saveflag = memberDao.saveMember(listExcel.get(i));
						if(!saveflag){
							returnMap.put("result", "fail");
							returnMap.put("errMsg",excelMap.get("errMsg"));
						}else{
							returnMap.put("result", "success");
						}*/
					}
				}
			}if(String.valueOf(excelMap.get("flag")).equals("success")){
				//说明当前用户要导入学生所属班级不存在
				returnMap.put("result","success");
			}if(listExcel==null||listExcel.size()==0&&!(String.valueOf(excelMap.get("flag")).equals("success"))){
				returnMap.put("result","fail");
				returnMap.put("errMsg",excelMap.get("errMsg"));

			}
		}else{
			returnMap.put("result","fail");
			if(returnMap.get("errMsg")!=""&&returnMap.get("errMsg")!=null){

			}else{
				returnMap.put("errMsg",excelMap.get("errMsg"));
			}

		}

		return returnMap;
	}
	/*测试导入课程*/
	/*public  void imCourseExcel(String file) throws Exception{
		this.getAllCourseByExcel(file);
	}

	public void getAllCourseByExcel(String file){
		Map<String, Object> returnMap = new HashMap<String,Object>();
		List<Map<String,Object>> list = new ArrayList<Map<String, Object>>();
		try{
			Workbook rwb=Workbook.getWorkbook(new File(file));

			for (int i=0;i<rwb.getSheets().length;i++){
				//sheet名
				String courseName = rwb.getSheets()[i].getName();
				Sheet rs=rwb.getSheet(i);
				int clos=rs.getColumns();//得到所有的列
				int rows=rs.getRows();//得到所有的行
				int newRow = PubMethods.getCourseNewRows(rows, rs);
				ok:
				for (int k = 0; k < newRow; k++){
					Map<String,Object> finalMap = new HashMap<String, Object>();
					for (int j = 1; j < 3; j++){
						//章节类型
						int type=0;
						int addTestMark=0;
						String coursewareName="";
						String videoName = "";
						String homeworkName = "";
						String homeworkNameDoc = "";
						String courseMaterialName = "";
						String courseAnswerName = "";
						String experimentName = "";
						String coursewareNameHtml = "";
						String homeworkNameHtml = "";
						String courseMaterialNameHtml = "";
						String courseAnswerNameHtml = "";
						String testNameHtml = "";
						String packageFile = "";
						String testDocName = "";
						Map<String, Object> resultMap = new HashMap<String,Object>();
						String charpterName=rs.getCell(j++, k).getContents().trim();//默认最左边编号也算一列 所以这里得j++
						String typeName = rs.getCell(j++, k).getContents().trim();
						if(charpterName.equals("")||charpterName.equals(null)||charpterName.equals("")||charpterName.equals(null)){
							returnMap.put("flag", "error");
							returnMap.put("errMsg", "章节相关信息不能为空，导入课程失败");
							returnMap.put("list", null);
							break ok;
						}
						if(typeName.equals("理论")) {
							type=2;
							addTestMark=2;
							coursewareName = courseName+"-"+charpterName+"-学习课件.pptx";
							courseMaterialName = courseName+"-"+charpterName+"-备课材料.docx";
							homeworkName = courseName+"-"+charpterName+"-课后习题.docx";
							homeworkNameDoc = courseName+"-"+charpterName+"-课后习题.docx";
							courseAnswerName = courseName+"-"+charpterName+"-课后习题答案.docx";
							coursewareNameHtml = courseName+"-"+charpterName+"-学习课件.pdf";
							homeworkNameHtml = courseName+"-"+charpterName+"-课后习题.html";
							courseMaterialNameHtml = courseName+"-"+charpterName+"-备课材料.html";
							courseAnswerNameHtml = courseName+"-"+charpterName+"-课后习题答案.html";
							finalMap.put("coursewareName",coursewareName);
							finalMap.put("courseMaterialName",courseMaterialName);
							finalMap.put("homeworkName",homeworkName);
							finalMap.put("homeworkNameDoc",homeworkNameDoc);
							finalMap.put("courseAnswerName",courseAnswerName);
							finalMap.put("experimentName",experimentName);
							finalMap.put("coursewareNameHtml",coursewareNameHtml);
							finalMap.put("homeworkNameHtml",homeworkNameHtml);
							finalMap.put("courseMaterialNameHtml",courseMaterialNameHtml);
							finalMap.put("courseAnswerNameHtml",courseAnswerNameHtml);
						}
						if(typeName.equals("理论+课程材料")) {
							type=2;
							addTestMark=2;
							coursewareName = courseName+"-"+charpterName+"-学习课件.pptx";
							courseMaterialName = courseName+"-"+charpterName+"-备课材料.docx";
							homeworkName = courseName+"-"+charpterName+"-课后习题.docx";
							homeworkNameDoc = courseName+"-"+charpterName+"-课后习题.docx";
							courseAnswerName = courseName+"-"+charpterName+"-课后习题答案.docx";
							coursewareNameHtml = courseName+"-"+charpterName+"-学习课件.pdf";
							homeworkNameHtml = courseName+"-"+charpterName+"-课后习题.html";
							courseMaterialNameHtml = courseName+"-"+charpterName+"-备课材料.html";
							courseAnswerNameHtml = courseName+"-"+charpterName+"-课后习题答案.html";
							packageFile = courseName+"-"+charpterName+"-课程材料.rar";
							finalMap.put("coursewareName",coursewareName);
							finalMap.put("courseMaterialName",courseMaterialName);
							finalMap.put("homeworkName",homeworkName);
							finalMap.put("homeworkNameDoc",homeworkNameDoc);
							finalMap.put("courseAnswerName",courseAnswerName);
							finalMap.put("experimentName",experimentName);
							finalMap.put("coursewareNameHtml",coursewareNameHtml);
							finalMap.put("homeworkNameHtml",homeworkNameHtml);
							finalMap.put("courseMaterialNameHtml",courseMaterialNameHtml);
							finalMap.put("courseAnswerNameHtml",courseAnswerNameHtml);
							finalMap.put("packageFile",packageFile);
						}
						if(typeName.equals("实验")) {
							type=1;
							addTestMark=1;
							testDocName = courseName+"-"+charpterName+"-实验手册.docx";
							testNameHtml = courseName+"-"+charpterName+"-实验手册.html";
							videoName = courseName+"-"+charpterName+"-实验视频.mp4";
							finalMap.put("testNameHtml",testNameHtml);
							finalMap.put("videoName",videoName);
							finalMap.put("testDocName",testDocName);
						}
						if(typeName.equals("实验+课程材料")) {
							type=1;
							addTestMark=1;
							testDocName = courseName+"-"+charpterName+"-实验手册.docx";
							testNameHtml = courseName+"-"+charpterName+"-实验手册.html";
							videoName = courseName+"-"+charpterName+"-实验视频.mp4";
							packageFile = courseName+"-"+charpterName+"-课程材料.rar";
							finalMap.put("packageFile",packageFile);
							finalMap.put("testNameHtml",testNameHtml);
							finalMap.put("videoName",videoName);
							finalMap.put("testDocName",testDocName);
						}
						if(typeName.equals("理论+实验")) {
							type=3;
							addTestMark=1;
							coursewareName = courseName+"-"+charpterName+"-学习课件.pptx";
							courseMaterialName = courseName+"-"+charpterName+"-备课材料.docx";
							homeworkName = courseName+"-"+charpterName+"-课后习题.docx";
							homeworkNameDoc = courseName+"-"+charpterName+"-课后习题.docx";
							courseAnswerName = courseName+"-"+charpterName+"-课后习题答案.docx";
							coursewareNameHtml = courseName+"-"+charpterName+"-学习课件.pdf";
							homeworkNameHtml = courseName+"-"+charpterName+"-课后习题.html";
							courseMaterialNameHtml = courseName+"-"+charpterName+"-备课材料.html";
							courseAnswerNameHtml = courseName+"-"+charpterName+"-课后习题答案.html";
							testDocName = courseName+"-"+charpterName+"-实验手册.docx";
							testNameHtml = courseName+"-"+charpterName+"-实验手册.html";
							videoName = courseName+"-"+charpterName+"-实验视频.mp4";
							finalMap.put("coursewareName",coursewareName);
							finalMap.put("courseMaterialName",courseMaterialName);
							finalMap.put("homeworkName",homeworkName);
							finalMap.put("homeworkNameDoc",homeworkNameDoc);
							finalMap.put("courseAnswerName",courseAnswerName);
							finalMap.put("experimentName",experimentName);
							finalMap.put("coursewareNameHtml",coursewareNameHtml);
							finalMap.put("homeworkNameHtml",homeworkNameHtml);
							finalMap.put("courseMaterialNameHtml",courseMaterialNameHtml);
							finalMap.put("courseAnswerNameHtml",courseAnswerNameHtml);
							finalMap.put("testNameHtml",testNameHtml);
							finalMap.put("videoName",videoName);
							finalMap.put("testDocName",testDocName);

						}
						finalMap.put("chapterName",charpterName);
						finalMap.put("type",type);
						finalMap.put("testAddress","");
						finalMap.put("addTestMark",addTestMark);
						finalMap.put("saveMark",1);
//						list.add(finalMap);
						//插入数据库
						chapterDao.addChapter(finalMap);

					}
				}

			}
		}catch (Exception e){
			e.printStackTrace();
		}

	}*/

	/**
	 * 查询指定目录中电子表格中所有的数据
	 * @param file 文件完整路径
	 * @return
	 */
	public  Map<String, Object> getAllByExcel(String file){
		List<Map<String, Object>> list=new ArrayList<Map<String, Object>>();
		Map<String, Object> returnMap = new HashMap<String,Object>();
		List<String> arr1 = new ArrayList<String>();
		List<String> arr2 = new ArrayList<String>();
		try {
			Workbook rwb=Workbook.getWorkbook(new File(file));
			Sheet rs=rwb.getSheet(0);
			int clos=rs.getColumns();//得到所有的列
			int rows=rs.getRows();//得到所有的行
			for (int j = 0; j < 6; j++){
				arr1.add(rs.getCell(j++, 1).getContents().trim());
				arr1.add(rs.getCell(j++, 1).getContents().trim());
				arr1.add(rs.getCell(j++, 1).getContents().trim());
				arr1.add(rs.getCell(j++, 1).getContents().trim());
				arr1.add(rs.getCell(j++, 1).getContents().trim());
				arr1.add(rs.getCell(j++, 1).getContents().trim());

				arr2.add("姓名");
				arr2.add("工号");
				arr2.add("性别");
				arr2.add("院系");
				arr2.add("专业");
				arr2.add("手机号");
			}
			//判断模板是否正确
			returnMap = PubMethods.isModel(arr1,arr2,rs);
			if(returnMap.size()!=0){
				return returnMap;
			}
			int newRow = PubMethods.getTeaMemNewRows(rows, rs);
			if(newRow<2){
				returnMap.put("flag", "fail");
				returnMap.put("errMsg", "数据为空，导入教师失败");
				returnMap.put("list", null);
				return returnMap;
			}
			ok:
			for (int i = 2; i <= newRow; i++) {
				for (int j = 0; j < 6; j++) {
					Map<String, Object> resultMap = new HashMap<String,Object>();
					//第一个是列数，第二个是行数
					String userName=rs.getCell(j++, i).getContents().trim();//默认最左边编号也算一列 所以这里得j++
					String stuorteaId=rs.getCell(j++, i).getContents().trim();
					String userSex=rs.getCell(j++, i).getContents().trim();
					String departmentName=rs.getCell(j++, i).getContents().trim();
					String professionName=rs.getCell(j++, i).getContents().trim();
					String telephoneNum=rs.getCell(j++, i).getContents().trim();
					//查询这条记录是否已存在
					List<Map<String, Object>> memberList = memberDao.getMemberByStuorteaId(stuorteaId);
					if(memberList!=null&&memberList.size()!=0){
						returnMap.put("flag", "fail");
						returnMap.put("errMsg", "第"+(i+1)+"行教师工号已存在，导入教师失败");
						returnMap.put("list", null);
						break ok;
					}
					if(PubMethods.isSpecialChar(stuorteaId)||PubMethods.isSpecialChar(userName)
							||PubMethods.isSpecialChar(userSex)||PubMethods.isSpecialChar(departmentName)
							||PubMethods.isSpecialChar(professionName)||PubMethods.isSpecialChar(telephoneNum)){
						returnMap.put("flag", "fail");
						returnMap.put("errMsg", "第"+(i+1)+"行教师不能输入特殊字符，导入教师失败");
						returnMap.put("list", null);
						break ok;
					}
					if(userName.equals("")||userName.equals(null)){
						returnMap.put("flag", "fail");
						returnMap.put("errMsg", "第"+(i+1)+"行教师姓名不能为空，导入教师失败");
						returnMap.put("list", null);
						break ok;
					}else{
						if(userName.length()>20){
							returnMap.put("flag", "fail");
							returnMap.put("errMsg", "第"+(i+1)+"行教师姓名不能超过20个字，导入教师失败");
							returnMap.put("list", null);
							break ok;
						}
						if(stuorteaId.equals("")||stuorteaId.equals(null)){
							returnMap.put("flag", "fail");
							returnMap.put("errMsg", "第"+(i+1)+"行教师工号不能为空，导入教师失败");
							returnMap.put("list", null);
							break ok;
						}else{
							if(stuorteaId.length()>15||stuorteaId.length()<1){
								returnMap.put("flag", "fail");
								returnMap.put("errMsg",  "第"+(i+1)+"行教师工号请输入1-15位数字或英文，导入教师失败");
								returnMap.put("list", null);
								break ok;
							}else{
								boolean idFlag = PubMethods.isStrChinese(stuorteaId);
								if(!idFlag){

									if(userSex.equals("")||userSex.equals(null)){
										returnMap.put("flag", "fail");
										returnMap.put("errMsg", "第"+(i+1)+"行教师性别不能为空，导入教师失败");
										returnMap.put("list", null);
										break ok;
									}else{
										if(!userSex.equals("女")&&!userSex.equals("男")){
											returnMap.put("flag", "fail");
											returnMap.put("errMsg",  "第"+(i+1)+"行教师性别输入不正确，导入教师失败");
											returnMap.put("list", null);
											break ok;
										}
										String sex = "m";
										if(userSex.equals("女")){
											sex="f";
										}


										if(departmentName.equals("")||departmentName.equals(null)){
											returnMap.put("flag", "fail");
											returnMap.put("errMsg",  "第"+(i+1)+"行教师院系不能为空，导入教师失败");
											returnMap.put("list", null);
											break ok;
										}else{
											Map<String, Object> paramMap = new HashMap<String,Object>();
											//通过院系名查询院系id
											List<Map<String, Object>> departList = new ArrayList<Map<String, Object>>();
											paramMap.put("departmentName", departmentName);
											departList=departMentDao.getDepartmentByName(paramMap);
											int departmentId = 0;
											int professionId = 0;
											int prodepartmentId = 0;
											if(departList!=null&&departList.size()!=0){
												departmentId = Integer.parseInt(String.valueOf(departList.get(0).get("departmentId")));
												if(professionName.equals("")||professionName.equals(null)){
													returnMap.put("flag", "fail");
													returnMap.put("errMsg",  "第"+(i+1)+"行教师专业不能为空，导入教师失败");
													returnMap.put("list", null);
													break ok;
												}else{
													//通过专业名查询专业id
													List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
													paramMap.put("professionName", professionName);
													returnList=professionDao.getProfessionList(paramMap);
													if(returnList!=null&&returnList.size()!=0){
														professionId = Integer.parseInt(String.valueOf(returnList.get(0).get("professionId")));
														prodepartmentId = Integer.parseInt(String.valueOf(returnList.get(0).get("departmentId")));
														//查询当前专业所属院系是否和填写的院系相符
														if(departmentId==prodepartmentId){
															if(returnList!=null&&returnList.size()!=0&&departList!=null&&departList.size()!=0){
                                                		   /*	if(telephoneNum.equals("")||telephoneNum==null){
																returnMap.put("flag", "error");
																returnMap.put("errMsg", "手机号不能为空，导入教师失败");
																list = null;
																returnMap.put("list", list);
																break ok;

															}else {*/
																boolean telFlag = false;
																if(telephoneNum.equals("")||telephoneNum==null){
																	telFlag = true;
																}else{
																	telFlag= PhoneValidatorUtil.matchPhoneShowToast(telephoneNum);
																}

																if(telFlag){
																	resultMap.put("userName", userName);
																	resultMap.put("stuorteaId", stuorteaId);
																	resultMap.put("userSex", sex);
																	resultMap.put("professionId", professionId);
																	resultMap.put("departmentId", departmentId);
																	resultMap.put("telephoneNum", telephoneNum);
																	resultMap.put("password", "");
																	resultMap.put("roleId",2);
																	resultMap.put("depId", 0);
																	resultMap.put("staff_role", 1);
																	resultMap.put("headIcon", "");
																	resultMap.put("userContect", "");
																	resultMap.put("imageUrl", "teamr.jpg");
																	resultMap.put("mem_type", 2);//标识添加的是教师
																	list.add(resultMap);
																	returnMap.put("list", list);
																}else{
																	returnMap.put("flag", "fail");
																	returnMap.put("errMsg", "第"+(i+1)+"行教师手机号输入不正确，导入教师失败");
																	list = null;
																	returnMap.put("list", list);
																	break ok;
																}
//															}
															}
														}else{
															list = null;
															returnMap.put("flag", "fail");
															returnMap.put("errMsg",  "第"+(i+1)+"行教师填写院系中没有相应的专业，导入教师失败");
															returnMap.put("list", list);
															break ok;
														}
													}else{
														returnMap.put("flag", "fail");
														returnMap.put("errMsg",  "第"+(i+1)+"行教师信息中专业不存在，导入教师失败");
														list = null;
														returnMap.put("list", list);
														break ok;
													}

												}

											}else{
												returnMap.put("flag", "fail");
												returnMap.put("errMsg",  "第"+(i+1)+"行教师信息中院系不存在，导入教师失败");
												list = null;
												returnMap.put("list", list);
												break ok;
											}
										}
									}
								}else{
									returnMap.put("flag", "fail");
									returnMap.put("errMsg",  "第"+(i+1)+"行教师工号不能为中文，导入教师失败");
									list = null;
									returnMap.put("list", list);
									break ok;
								}
							}
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return returnMap;

	}

	/**
	 * 查询指定目录中电子表格中所有的数据
	 * @param file 文件完整路径
	 * @return
	 */
	public  Map<String, Object> getAllStudentByExcel(String file,int classId){
		List<Map<String, Object>> list=new ArrayList<Map<String, Object>>();
		Map<String, Object> returnMap = new HashMap<String,Object>();
		try {
			Workbook rwb=Workbook.getWorkbook(new File(file));
			Sheet rs=rwb.getSheet(0);

			int clos=rs.getColumns();//得到所有的列
			int rows=rs.getRows();//得到所有的行

//       int newRow = PubMethods.getMemNewRows(rows, rs);
			Map<String,Object> rowMap = PubMethods.getStuMemNewRows(rows, rs);

			int newRow = Integer.parseInt(String.valueOf(rowMap.get("newRow")));
			boolean rowFlag = (Boolean)rowMap.get("flag");
			int rowI = Integer.parseInt(String.valueOf(rowMap.get("i")));
			int count=0;
			if(newRow<2){
				returnMap.put("flag", "fail");
				returnMap.put("errMsg", "数据为空，导入学生失败");
				returnMap.put("list", null);
				return returnMap;
			}

			ok:
			for (int i = 2; i <= newRow; i++) {
				count++;
				if(count<newRow){
					oh:
					for (int j = 0; j < 4; j++) {
						Map<String, Object> resultMap = new HashMap<String,Object>();
						//第一个是列数，第二个是行数
						String stuorteaId=rs.getCell(j++, i).getContents().trim();//默认最左边编号也算一列 所以这里得j++
						String userName=rs.getCell(j++, i).getContents().trim();
						String userSex=rs.getCell(j++, i).getContents().trim();
						String telephoneNum=rs.getCell(j++, i).getContents().trim();
						if(stuorteaId.equals("")||stuorteaId.equals(null)){
							returnMap.put("flag", "fail");
							returnMap.put("errMsg", "第"+(i+1)+"行学生学号不能为空，导入学生失败");
							returnMap.put("list", null);
							break ok;
						}else{
							if(PubMethods.isSpecialChar(stuorteaId)||PubMethods.isSpecialChar(userName)||PubMethods.isSpecialChar(userSex)||PubMethods.isSpecialChar(telephoneNum)){
								returnMap.put("flag", "fail");
								returnMap.put("errMsg", "第"+(i+1)+"行学生信息不能输入特殊字符，导入学生失败");
								returnMap.put("list", null);
								break ok;
							}
							if(stuorteaId.length()>15||stuorteaId.length()<1){
								returnMap.put("flag", "fail");
								returnMap.put("errMsg", "第"+(i+1)+"行学生学号请输入1-15位数字或英文，导入学生失败");
								returnMap.put("list", null);
								break ok;
							}else{
								boolean idFlag = PubMethods.isStrChinese(stuorteaId);
								if(!idFlag){

									if(userName.equals("")||userName.equals(null)){
										returnMap.put("flag", "fail");
										returnMap.put("errMsg", "第"+(i+1)+"行学生姓名不能为空，导入学生失败");
										returnMap.put("list", null);
										break ok;
									}else{
										if(userName.length()>20){
											returnMap.put("flag", "fail");
											returnMap.put("errMsg", "第"+(i+1)+"行学生姓名不能超过20个字，导入学生失败");
											returnMap.put("list", null);
											break ok;
										}
										if(userSex.equals("")||userSex.equals(null)){
											returnMap.put("flag", "fail");
											returnMap.put("errMsg","第"+(i+1)+"行学生性别不能为空，导入学生失败");
											returnMap.put("list", null);
											break ok;
										}else{
											if(!userSex.equals("女")&&!userSex.equals("男")){
												returnMap.put("flag", "fail");
												returnMap.put("errMsg", "第"+(i+1)+"行学生性别输入不正确，导入学生失败");
												returnMap.put("list", null);
												break ok;
											}
											String sex = "m";
											if(userSex.equals("女")){
												sex="f";
											}
									   /*if(telephoneNum.equals("")||telephoneNum==null){
										   returnMap.put("flag", "error");
										   returnMap.put("errMsg", "手机号不能为空，导入学生失败");
										   list = null;
										   returnMap.put("list", list);
										   break ok;

									   }else{*/
											boolean telFlag = false;
											if(telephoneNum.equals("")||telephoneNum==null){
												telFlag = true;
											}else{
												telFlag = PhoneValidatorUtil.matchPhoneShowToast(telephoneNum);
											}

											if(telFlag){
												resultMap.put("userName", userName);
												resultMap.put("stuorteaId", stuorteaId);
												resultMap.put("userSex", sex);
												resultMap.put("professionId", 0);
												resultMap.put("departmentId", 0);
												resultMap.put("telephoneNum", telephoneNum);
												resultMap.put("password", "");
												resultMap.put("roleId",1);
												resultMap.put("depId", 0);
												resultMap.put("headIcon", "");
												resultMap.put("userContect", "");
												resultMap.put("imageUrl", "");
												list.add(resultMap);
												returnMap.put("list", list);
											}else{
												returnMap.put("flag", "fail");
												returnMap.put("errMsg", "第"+(i+1)+"行学生手机号输入不正确，导入学生失败");
												list = null;
												returnMap.put("list", list);
												break ok;
											}
//									   }

											//林大部分
//                                	   String className=rs.getCell(j++, i).getContents().trim();
											//通过班级名查询当前输入的班级是否和要导入班级相匹配
//                                	   List<Map<String,Object>> classList = classDao.getClassByClassName(className);
                                	   /*if(classList!=null&&classList.size()!=0){
                                		   if(Integer.valueOf(String.valueOf(classList.get(0).get("classId")))==classId){
                                			   telFlag = true;
                                		   }
                                    	   if(telFlag){
                                    		   resultMap.put("userName", userName);
                                               resultMap.put("stuorteaId", stuorteaId);
                                               resultMap.put("userSex", sex);
                                               resultMap.put("professionId", 0);
                                               resultMap.put("departmentId", 0);
                                               resultMap.put("telephoneNum", "");
                                               resultMap.put("password", "");
                                               resultMap.put("roleId",1);
                                               resultMap.put("depId", 0);
//                                               resultMap.put("age", finage);
                                               resultMap.put("headIcon", "");
                                               resultMap.put("userContect", "");
                                               resultMap.put("imageUrl", "");
                                               list.add(resultMap);
                                               returnMap.put("list", list);
                                    	   }else{

                                           }
                                	   }else{
										   returnMap.put("flag", "error");
										   returnMap.put("errMsg", "班级不存在，导入学生失败");
										   list = null;
										   returnMap.put("list", list);
                                		   break oh;
                                	   }*/

										}

									}

								}else{
									returnMap.put("flag", "fail");
									returnMap.put("errMsg","第"+(i+1)+ "行学生学号不能为中文，导入学生失败");
									list = null;
									returnMap.put("list", list);
									break ok;
								}
							}
						}
					}
				}else{
					break ok;
				}
			}

		} catch (Exception e) {
			//
			e.printStackTrace();
		}
		return returnMap;

	}

	/**
	 * 多个班级一起导入
	 * 查询指定目录中电子表格中所有的数据
	 * @param file 文件完整路径
	 * @return
	 */
	public  Map<String, Object> getAllStudentByManyClassExcel(String file){
		List<Map<String, Object>> list=new ArrayList<Map<String, Object>>();
		Map<String, Object> returnMap = new HashMap<String,Object>();
		List<String> arr1 = new ArrayList<String>();
		List<String> arr2 = new ArrayList<String>();
		try {
			Workbook rwb=Workbook.getWorkbook(new File(file));
			Sheet rs=rwb.getSheet(0);

			int clos=rs.getColumns();//得到所有的列
			int rows=rs.getRows();//得到所有的行
			Map<String,Object> rowMap = PubMethods.getStuMemNewRows(rows, rs);
			int newRow = Integer.parseInt(String.valueOf(rowMap.get("newRow")));
			boolean rowFlag = (Boolean)rowMap.get("flag");
			int rowI = Integer.parseInt(String.valueOf(rowMap.get("i")));
			int count=0;
			//判断模板是否正确
			for (int j = 0; j < 5; j++){
				arr1.add(rs.getCell(j++, 1).getContents().trim());
				arr1.add(rs.getCell(j++, 1).getContents().trim());
				arr1.add(rs.getCell(j++, 1).getContents().trim());
				arr1.add(rs.getCell(j++, 1).getContents().trim());
				arr1.add(rs.getCell(j++, 1).getContents().trim());

				arr2.add("学号");
				arr2.add("姓名");
				arr2.add("性别");
				arr2.add("手机号");
				arr2.add("班级");
			}
			//判断模板是否正确
			returnMap = PubMethods.isModel(arr1,arr2,rs);
			if(returnMap.size()!=0){
				return returnMap;
			}
			if(newRow<2){
				returnMap.put("flag", "fail");
				returnMap.put("errMsg", "数据为空，导入学生失败");
				returnMap.put("list", null);
				return returnMap;
			}

			ok:
			for (int i = 2; i <= newRow; i++) {
				count++;
				if(count<newRow){
					oh:
					for (int j = 0; j < 5; j++) {
						Map<String, Object> resultMap = new HashMap<String,Object>();
						//第一个是列数，第二个是行数
						String stuorteaId=rs.getCell(j++, i).getContents().trim();//默认最左边编号也算一列 所以这里得j++
						String userName=rs.getCell(j++, i).getContents().trim();
						String userSex=rs.getCell(j++, i).getContents().trim();
						String telephoneNum=rs.getCell(j++, i).getContents().trim();
						String className=rs.getCell(j++, i).getContents().trim();
//						String departmentName=rs.getCell(j++, i).getContents().trim();
//						String professionName=rs.getCell(j++, i).getContents().trim();
						//查询这条记录是否已存在
						List<Map<String, Object>> memberList = memberDao.getMemberByStuorteaId(stuorteaId);
						if(memberList!=null&&memberList.size()!=0){
							returnMap.put("flag", "fail");
							returnMap.put("errMsg", "第"+(i+1)+"行学生学号已存在，导入学生失败");
							returnMap.put("list", null);
							break ok;
						}
						if(stuorteaId.equals("")||stuorteaId.equals("null")||stuorteaId==null){
							returnMap.put("flag", "fail");
							returnMap.put("errMsg", "第"+(i+1)+"行学生学号不能为空，导入学生失败");
							returnMap.put("list", null);
							break ok;
						}else{
							if(PubMethods.isSpecialChar(stuorteaId)||PubMethods.isSpecialChar(userName)||PubMethods.isSpecialChar(userSex)||PubMethods.isSpecialChar(telephoneNum)
									||PubMethods.isSpecialChar(className)){
								returnMap.put("flag", "fail");
								returnMap.put("flag", "fail");
								returnMap.put("errMsg", "第"+(i+1)+"行学生信息不能输入特殊字符，导入学生失败");
								returnMap.put("list", null);
								break ok;
							}
							if(stuorteaId.length()>15||stuorteaId.length()<1){
								returnMap.put("flag", "fail");
								returnMap.put("errMsg", "第"+(i+1)+"行学生学号请输入1-15位数字或英文，导入学生失败");
								returnMap.put("list", null);
								break ok;
							}else{
								boolean idFlag = PubMethods.isStrChinese(stuorteaId);
								if(!idFlag){

									if(userName.equals("")||userName.equals("null")||userName==null){
										returnMap.put("flag", "fail");
										returnMap.put("errMsg", "第"+(i+1)+"行学生姓名不能为空，导入学生失败");
										returnMap.put("list", null);
										break ok;
									}else{
										if(userName.length()>20){
											returnMap.put("flag", "fail");
											returnMap.put("errMsg", "第"+(i+1)+"行学生姓名不能超过20个字，导入学生失败");
											returnMap.put("list", null);
											break ok;
										}
										if(userSex.equals("")||userSex.equals("null")||userSex==null){
											returnMap.put("flag", "fail");
											returnMap.put("errMsg","第"+(i+1)+"行学生性别不能为空，导入学生失败");
											returnMap.put("list", null);
											break ok;
										}else{
											if(!userSex.equals("女")&&!userSex.equals("男")){
												returnMap.put("flag", "fail");
												returnMap.put("errMsg", "第"+(i+1)+"行学生性别输入不正确，导入学生失败");
												returnMap.put("list", null);
												break ok;
											}
											String sex = "m";
											if(userSex.equals("女")){
												sex="f";
											}
											boolean telFlag = false;
											if(telephoneNum.equals("")||telephoneNum==null||telephoneNum.equals("null")){
												telFlag = true;
											}else{
												telFlag = PhoneValidatorUtil.matchPhoneShowToast(telephoneNum);
											}
											if(!telFlag){
												returnMap.put("flag", "fail");
												returnMap.put("errMsg", "第"+(i+1)+"行学生手机号输入不正确，导入学生失败");
												list = null;
												returnMap.put("list", list);
												break ok;
											}
											if(className.equals("")||className==null||className.equals("null")){
												returnMap.put("flag", "fail");
												returnMap.put("errMsg", "第"+(i+1)+"行学生班级不能为空，导入学生失败");
												list = null;
												returnMap.put("list", list);
												break ok;
											}
											if(className.length()>20){
												returnMap.put("flag", "fail");
												returnMap.put("errMsg", "第"+(i+1)+"行学生班级名称超出限制，导入学生失败");
												list = null;
												returnMap.put("list", list);
												break ok;
											}
											/*if(departmentName.equals("")||departmentName==null){
												returnMap.put("flag", "error");
												returnMap.put("errMsg", "第"+(i+1)+"行学生院系不能为空，导入学生失败");
												list = null;
												returnMap.put("list", list);
												break ok;
											}
											if(professionName.equals("")||professionName==null){
												returnMap.put("flag", "error");
												returnMap.put("errMsg", "第"+(i+1)+"行学生专业不能为空，导入学生失败");
												list = null;
												returnMap.put("list", list);
												break ok;
											}*/
											//通过班级名称查询班级id
											List<Map<String, Object>> classList = classDao.getClassByClassName(className);
											if(classList==null||classList.size()==0){
												returnMap.put("flag", "fail");
												returnMap.put("errMsg", "第"+(i+1)+"行学生班级不存在，导入学生失败");
												list = null;
												returnMap.put("list", list);
												break ok;
											}
											//通过院系名称查询院系id
											Map<String,Object> idMap = new HashMap<String, Object>();
											idMap.put("classId",classList.get(0).get("classId"));
											//查询当前班级所属的院系和专业
											Map<String,Object> classMap = classDao.getDeAndProByClassId(idMap);
//											idMap.put("departmentName",departmentName);
//											idMap.put("professionName",professionName);
											/*List<Map<String,Object>> departmentList = departMentDao.getDepartmentByName(idMap);
											if(departmentList==null||departmentList.size()==0){
												returnMap.put("flag", "error");
												returnMap.put("errMsg", "第"+(i+1)+"行学生院系不存在，导入学生失败");
												list = null;
												returnMap.put("list", list);
												break ok;
											}
											//通过专业名称获取专业id
											List<Map<String,Object>> professionList = professionDao.getProfessionByName(idMap);
											if(professionList==null||professionList.size()==0){
												returnMap.put("flag", "error");
												returnMap.put("errMsg", "第"+(i+1)+"行学生专业不存在，导入学生失败");
												list = null;
												returnMap.put("list", list);
												break ok;
											}*/
											resultMap.put("userName", userName);
											resultMap.put("stuorteaId", stuorteaId);
											resultMap.put("userSex", sex);
											resultMap.put("professionId", 0);
											resultMap.put("departmentId", 0);
											resultMap.put("telephoneNum", telephoneNum);
											resultMap.put("password", "");
											resultMap.put("roleId",1);
											resultMap.put("depId", 0);
											resultMap.put("headIcon", "");
											resultMap.put("userContect", "");
											resultMap.put("imageUrl", "");
											resultMap.put("classId",classList.get(0).get("classId"));
											resultMap.put("departmentId",classMap.get("departmentId"));
											resultMap.put("professionId",classMap.get("professionId"));
											list.add(resultMap);
											returnMap.put("list", list);
										}

									}
								}else{
									returnMap.put("flag", "fail");
									returnMap.put("errMsg","第"+(i+1)+ "行学生学号不能为中文，导入学生失败");
									list = null;
									returnMap.put("list", list);
									break ok;
								}
							}
						}
					}
				}else{
					break ok;
				}
			}

		} catch (Exception e) {
			//
			e.printStackTrace();
		}
		return returnMap;

	}


	/**date：2017-04-07 xzx
	 * @description 查询某班级详细信息
	 * @param classId
	 * @return Map
	 * @throws Exception
	 */
	public Map<String, Object> getClassMsgById(Map<String, Object> paramMap) throws Exception{

		Map<String, Object> map = new HashMap<String , Object>();
		try{
			map = classDao.getClassMsgById(paramMap);
		}catch(Exception e){
			throw e;
		}
		return map;
	}

	/**date：2017-06-13 xzx
	 * @description 查询某班级详细信息 只有班级名字
	 * @param paramMap classId
	 * @return Map
	 * @throws Exception
	 */
	public Map<String, Object> getClassNameById(Map<String, Object> paramMap) throws Exception{

		Map<String, Object> map = new HashMap<String , Object>();
		try{
			map = classDao.getClassNameById(paramMap);
		}catch(Exception e){
			throw e;
		}
		return map;
	}

	/**xzx
	 * @return  判断一个数组里是否有重复值
	 * @throws Exception
	 * @throws IOException
	 */
	public boolean checkRepeat(List<Map<String, Object>> paramList) throws Exception{

		Set<Integer> set = new HashSet<Integer>();
		boolean result = false;
		try{
			for(Map<String, Object> map : paramList){
				int courseId = Integer.parseInt(map.get("courseId").toString());
				set.add(courseId);
			}
			//有重复
			if(set.size() != paramList.size()){
				result =  false;
				//不重复
			}else{
				result = true;
			}
		}catch(Exception e){
			throw e;
		}
		return result;
	}

	/**xzx
	 * @return  查询得到的课程老师之间关系是否正确，如有一条不正确返回失败
	 * @throws Exception
	 * @throws IOException
	 */
	public boolean checkRightMark(List<Map<String, Object>> paramList) throws Exception{

		boolean result = false;
		int rightLength = 0;
		try{
			for(Map<String, Object> map : paramList){
				map.put("couSelectMark", 1);//注意找等于1或3的
				Map<String, Object> teacherMap = relationDao.getTeacherByCourseIdAndMark(map);
				//没有关联关系的课程可以
				if(teacherMap == null){
					rightLength += 1;
				}else{
					//课程有上课老师，并且上课老师还是这个老师，可以
					if(((String)teacherMap.get("stuorteaId")).equals((String)map.get("stuorteaId"))){
						rightLength += 1;
					}
				}
			}
			if(rightLength == paramList.size()){
				result = true;
			}

		}catch(Exception e){
			throw e;
		}
		return result;
	}

	/**date：2017-06-08 xzx
	 * @description 修改班级的位置，返回关联信息，下面带加号的 ,参数是班级id
	 * @param paramMap classId
	 * @return Map
	 * @throws Exception
	 */
	public List<Map<String, Object>> getClassRelation(Map<String, Object> paramMap) throws Exception{

		List<Map<String, Object>> list = new ArrayList<Map<String , Object>>();
		try{
			list = classDao.getClassRelation(paramMap);
			List<Map<String, Object>> relationList;
			//0612 add
			if(!CollectionUtils.isEmpty(list)){
				for(Map<String, Object> map : list){
					relationList = relationDao.getRelCourseClass(map);
					if(!CollectionUtils.isEmpty(relationList)) map.put("classEndMark", relationList.get(0).get("classEndMark"));
				}
			}
			//0612 add end
		}catch(Exception e){
			throw e;
		}
		return list;
	}

	/**date：2017-06-08 xzx
	 * @description 修改班级的时候删除一条关联信息的删除方法 并且恢复关联数据
	 * @param paramMap classId stuorteaId courseId
	 * @return Map
	 * @throws Exception
	 */
	public Map<String, Object> delClassRelations(Map<String, Object> paramMap) throws Exception{
		Map<String, Object> returnMap = new HashMap<>();
		boolean result = false;
		try{
			if(paramMap.get("delList") != null){
				//删除文件信息
				DelWorkFileUtil delWorkFileUtil = new DelWorkFileUtil();
				String[] keysArray = {"server_address", "project_name","tomcatUrl"};
				Map<String, Object> pathMap = ConfigFileUtil.getFileMessage("UtilFile.properties", keysArray);
				String path =(String)pathMap.get("tomcatUrl")+(String)pathMap.get("project_name")+"upload/stuwork";
				List<Map<String, Object>> delList = (List<Map<String, Object>>)paramMap.get("delList");
				List<Map<String, Object>> teachList = new ArrayList<Map<String, Object>>();
				for(Map<String, Object> map : delList){
					//获取是这些班级是否存在以考试的班级
					List<String> list = new ArrayList<>();
					list.add(String.valueOf(map.get("classId")));
					List<Map<String, Object>> classList = classDao.getClassStateList(list);
					if(classList!=null&&classList.size()!=0){
						returnMap.put("result",false);
						returnMap.put("failMsg","班级处于考试状态不可删除");
						return returnMap;
					}
					//删除这个教师教的这个课的这个班级下的所有学生的作业信息
					delWorkFileUtil.delFileList(classDao.getCouClassTeaWork(map), new String[]{"taskAddress","convertFile"}, path);
					//删除classrelation表里面的数据,参数是班级id，课程id，老师id
					classDao.delClassRelation(map);
					//删除这个教师这个课的权重
					map.put("courseMark",1);
//					sourceDao.delSorceSetById(map);
					if(relStuClassDao.getAllClassStateByTeaCouId(map)!=null&&relStuClassDao.getAllClassStateByTeaCouId(map).size()!=0){
						/**sy改**/
						//删除这个教师教的这个课的这个班级与试卷的关联信息
						List<Map<String,Object>> onlineListOne = relStuClassDao.getAllClassStateByTeaCouId(map);
						map.put("list",onlineListOne);
						questionDao.delreClassOnlineByOnIdList(map);
						//删除班级对应的试卷
						questionDao.deleteOnlineByClassIdAndOnId(map);
						//判断这个教师这个课存在的试卷是否还寻在与班级有关联关系，如果当前教师彻底不教这个课了，则将试卷删除
						List<Map<String,Object>> onlineList = relStuClassDao.getAllClassStateByTeaCouId(map);
						if(onlineList==null||onlineList.size()==0){
							//说明当前教师彻底不教这个课了，则将试卷、成绩等删除
							//通过试卷主键查询stuanswerquestion表中的学生id
							List<Map<String,Object>> stuIdList = questionDao.getStuAnswerByOnIdListObject(onlineListOne);
							if(stuIdList!=null&&stuIdList.size()!=0){
								//删除这个教师教的这个课的所有学生的成绩信息
								sourceDao.delStuSoruceBystuorteaId(stuIdList);
								//删除这个教师教的这个课的这个班级下的所有考试学生的答题信息
								map.put("onlineMark",1);
								map.put("stuIdList",stuIdList);
								questionDao.delStuanswerByOnlineIdTwo(map);
							}

							//说明这个教师这个课程的这个试卷已经不存在和班级有关联关系（相当于这个教师彻底不教这个课了），则将这个课的这个教师的这个试卷删除
							questionDao.delOnlineByTeaId(map);

						}else{
							for(Map<String,Object> onlineMap:onlineList){
								//这个教师这个课存在的试卷是否还存在与班级有关联关系
								List<Map<String,Object>> onlineListTemp = questionDao.getreClassOnlineByTeaId(onlineMap);
								if(onlineListTemp==null||onlineListTemp.size()==0){
									//通过试卷主键查询stuanswerquestion表中的学生id
									List<Map<String,Object>> stuIdList = questionDao.getStuIdListByOnId(onlineMap);
									if(stuIdList!=null&&stuIdList.size()!=0){
										//删除这个教师教的这个课的所有学生的成绩信息
										sourceDao.delStuSoruceBystuorteaId(stuIdList);
									}
									//删除这个教师教的这个课的这个班级下的所有考试学生的答题信息
									questionDao.delStuanswerByOnlineIdTwo(onlineMap);
									//说明这个教师这个课程的这个试卷已经不存在和班级有关联关系（相当于这个教师彻底不教这个课了），则将这个课的这个教师的这个试卷删除
									questionDao.delOnlineByTeaId(onlineMap);
								}
							}
						}

					}
					//删除教师与班级的关系
					relationDao.delClassReTeacherNew(map);
					//删除课与班级的关系,参数为课程id，班级Id
					relationDao.delCourseRelClass(map);
					//恢复关联信息开始
					//查询这个课程的录入人id
					Map<String, Object> courseDetail = courseDao.getCourseDetail(map);
					//查询这个课这个老师之间的关系
					List<Map<String, Object>> relationList = relationDao.getRelCourseTea(map);
					if(relationList != null && relationList.size() != 0){
						//如果原来的关系是3，将关系改为2，并且不删除关系
						if(Integer.parseInt(relationList.get(0).get("couSelectMark").toString()) == 3){
							//查看这个课这个老师还有没有教这个课的正常类型的课信息
							teachList = relationDao.getTeachMsgIdByCouIdSid(map);
							if(teachList == null || teachList.size() == 0){
								map.put("selectMark", 2);
								relationDao.saveSelectMark(map);
							}
						}else{
							//如果要删除的信息是录入人的授课信息
							if(((String)courseDetail.get("stuorteaId")).equals((String)map.get("stuorteaId"))){
								//查询这个教师还有没有教这个课程
								teachList = relationDao.getTeachCourseListById(map);
								//如果没有教这个课了，inmark=1
								if(teachList == null || teachList.size() == 0){
									map.put("inMark", 1);
									relationDao.saveInMarkReMark(map);
								}
							}else{
								//查询这个教师这个课还有没有关联，如果没有了，删除
								List<Map<String, Object>> reTeaClassList = relationDao.getCourseReTeacher(map);
								if(reTeaClassList == null || reTeaClassList.size() == 0){
									//不是录入教师，删除教师与课程之间的关系
									relationDao.delCourseReTeacher(map);
								}
							}
						}
					}
					//修改课程类型标志
					//查询这个课的正常类型有没有人教，
					if(Integer.parseInt(courseDetail.get("selectMark").toString()) == 3){
						//查询教师排课类型的这个课程是否有人教
						teachList = relationDao.getTeachMsgIdByCouId(map);
						//如果没有正常教课类型的授课信息了，类型改为2
						if(teachList == null || teachList.size() == 0){
							map.put("selectMark", 2);
							courseDao.saveSelectMark(map);
						}
					}

			/*		if(((String)courseDetail.get("stuorteaId")).equals((String)map.get("stuorteaId"))){
						//查询
						map.put("inMark", 1);
						relationDao.saveInMarkReMark(map);
					//不是录入老师
					}else{
						if(relationList != null){
							if(relationList.size() != 0){
								//如果原来的关系是3，将关系改为2，并且不删除关系
								if(Integer.parseInt(relationList.get(0).get("couSelectMark").toString()) == 3){
									map.put("selectMark", 2);
									relationDao.saveSelectMark(map);
								}else{
									//删除教师与课程之间的关系
									relationDao.delCourseReTeacher(map);
								}
							}
						}
					}*/
					//删除这个班级下学生与这个课程的关联关系
					relationDao.delMyStuCourseRel(map);
					//删除课表中属于这个课的课表信息，标识是1
					map.put("couSelectMark", 1);
					relationDao.delRelation(map);
				}
				result = true;
			}
			returnMap.put("result",result);
			returnMap.put("failMsg","");
		}catch(Exception e){
			throw e;
		}
		return returnMap;
	}

	/**date：2017-06-08 xzx
	 * @description 获取该班级对应的课程以及任课教师信息
	 * @param paramMap classId
	 * @return Map
	 * @throws Exception
	 */
	public List<Map<String, Object>> getCourseByClassId(Map<String, Object> paramMap) throws Exception{

		List<Map<String, Object>> list = new ArrayList<Map<String , Object>>();
		try{
			list = classDao.getCourseByClassId(paramMap);
		}catch(Exception e){
			throw e;
		}
		return list;
	}

	/**date：2017-06-09 xzx
	 * @description 获取某个课程的教师排课类型的上课教师
	 * @param paramMap courseId
	 * @return Map
	 * @throws Exception
	 */
	public Map<String, Object> getTeacherByCourseIdAndMark(Map<String, Object> paramMap) throws Exception{

		Map<String, Object> map = new HashMap<String, Object>();
		try{
			map = relationDao.getTeacherByCourseIdAndMark(paramMap);
		}catch(Exception e){
			throw e;
		}
		return map;
	}

	/** xzx
	 * @description 获取是否存在这些班级的任课关联信息
	 * @param paramMap courseId
	 * @return Map
	 * @throws Exception
	 */
	public void getDelClassMark(String jsonStr, HttpServletResponse res) {

		Map<String, Object> map = new HashMap<String, Object>();
		ObjectMapper mapper = new ObjectMapper();
		try{
			List<String> list = new ArrayList<String>();
			list = mapper.readValue(jsonStr, list.getClass());
			//获取这些班级是否有学生、
			List<String> stuList = classDao.getIsClassStu(list);
			List<Map<String, Object>> relationList = classDao.getDelClassMark(list);
			if((relationList == null || relationList.size() == 0)&&(stuList==null||stuList.size()==0)){
				map.put("relationMark", 0);
			}if(stuList!=null&&stuList.size()!=0){
				map.put("relationMark",2);
				memberActionImpl.delStuMethod(stuList,1);

			}if(relationList!=null&&relationList.size()!=0){
				map.put("relationMark", 1);
				//查询有关联的班级的名字
				List<Map<String, Object>> nameList = classDao.getRelaClassNameList(list);
				StringBuffer names = new StringBuffer();
				for(Map<String, Object> mapName : nameList){
					names.append(mapName.get("className")).append(",");
				}
				names.replace(names.length() - 1, names.length(), "");
				map.put("classNames", names.toString());
			}if((relationList!=null&&relationList.size()!=0)&&(stuList!=null&&stuList.size()!=0)){
				map.put("relationMark", 3);
			}
			map.put("result", "success");
			courseActionImpl.responseStream(res, mapper.writeValueAsString(map));
		}catch(Exception e){
			e.printStackTrace();
			map.put("result", "fail");
			try {
				courseActionImpl.responseStream(res, mapper.writeValueAsString(map));
			} catch (JsonProcessingException e1) {
				e1.printStackTrace();
			}
		}
	}

	/**
	 * @param stuorteaId
	 * @return  通过教师id获取当前教师所教授的班级信息。
	 * @throws IOException
	 */
	public Map<String, Object> getClassListByTeaId(Map<String, Object> paramMap) throws Exception {

		Map<String, Object> returnMap = new HashMap<String, Object>();
		try {

			//查询所有班级
			List<Map<String, Object>> classList = classDao.getClassListByTeaId(paramMap);
			returnMap.put("classList", classList);
		} catch (Exception e) {
			throw e;
		}
		return returnMap;
	}

}
